xm dump command add on
authorroot@procyon <root@procyon>
Thu, 14 Sep 2006 07:19:38 +0000 (08:19 +0100)
committerroot@procyon <root@procyon>
Thu, 14 Sep 2006 07:19:38 +0000 (08:19 +0100)
xm dump-core [-L|--live][-C| --crash] <domID> [output path]

-L| --live Live dump:
        By default, xm dump does an xm pause, unpause before and
        after taking the dump, respectively.  This option disables
        the pause/unpause and simply takes the dump.

-C :| --crash crash dump:
        This executes an xm destroy after the dump file is complete.

The output path is optional, and if it is not specified, the path will be
/var/xen/dump/<domU name>.<domU ID>.core

This command uses the existant dumpCore(), which has been used for
coredump when a domU crashed.

Signed-off-by: Ken Hironaka <hironaka.ken@soft.fujitsu.com>
Signed-off-by: Akio Takebe <takebe_akio@jp.fujitsu.com>
tools/python/xen/xend/XendDomain.py
tools/python/xen/xend/XendDomainInfo.py
tools/python/xen/xm/main.py

index e9eb8981d2b6560420117410191f35bcdc3b4bce..94fadcf84d80f038b8df37491a7d0d440ea1341f 100644 (file)
@@ -390,6 +390,22 @@ class XendDomain:
         except Exception, ex:
             raise XendError(str(ex))
 
+    def domain_dump(self, domid, filename, live, crash):
+        """Dump domain core."""
+
+        dominfo = self.domain_lookup_by_name_or_id_nr(domid)
+        if not dominfo:
+            raise XendInvalidDomain(str(domid))
+
+        if dominfo.getDomid() == PRIV_DOMAIN:
+            raise XendError("Cannot dump core for privileged domain %s" % domid)
+
+        try:
+            log.info("Domain core dump requested for domain %s (%d) live=%d crash=%d.",
+                     dominfo.getName(), dominfo.getDomid(), live, crash)
+            return dominfo.dumpCore(filename)
+        except Exception, ex:
+            raise XendError(str(ex))
 
     def domain_destroy(self, domid):
         """Terminate domain immediately."""
index 6a7ad82f9ab529b31ec8df153b99eba8f72397d2..e1e9207041df49df694d1e9c4b334dffd15a1db6 100644 (file)
@@ -977,11 +977,12 @@ class XendDomainInfo:
         self.restart(True)
 
 
-    def dumpCore(self):
+    def dumpCore(self,corefile=None):
         """Create a core dump for this domain.  Nothrow guarantee."""
         
         try:
-            corefile = "/var/xen/dump/%s.%s.core" % (self.info['name'],
+            if not corefile:
+                corefile = "/var/xen/dump/%s.%s.core" % (self.info['name'],
                                                      self.domid)
             xc.domain_dumpcore(self.domid, corefile)
 
index a489498969e6c1eff117d81281e19bb2de038992..aafdf2de3462dc585ff5cda94066a5f5948089e6 100644 (file)
@@ -57,6 +57,9 @@ console_help = "console <DomId>                  Attach to domain DomId's consol
 create_help =  """create [-c] <ConfigFile>
                [Name=Value]..       Create a domain based on Config File"""
 destroy_help = "destroy <DomId>                  Terminate a domain immediately"
+dump_core_help =   """dump-core [-L|--live][-C|--crash]
+            <DomId> [FileName]      Dump core of the specified domain"""
+
 help_help =    "help                             Display this message"
 list_help =    "list [--long] [DomId, ...]       List information about domains"
 list_label_help = "list [--label] [DomId, ...]      List information about domains including their labels"
@@ -138,6 +141,7 @@ short_command_list = [
     "console",
     "create",
     "destroy",
+    "dump-core",
     "help",
     "list",
     "mem-set",
@@ -159,6 +163,7 @@ domain_commands = [
     "destroy",
     "domid",
     "domname",
+    "dump-core",
     "list",
     "list_label",
     "mem-max",
@@ -590,6 +595,43 @@ def xm_unpause(args):
 
     server.xend.domain.unpause(dom)
 
+def xm_dump_core(args):
+    arg_check(args, "dump-core",1,3)
+    live = False
+    crash = False
+    import getopt
+    (options, params) = getopt.gnu_getopt(args, 'LC', ['live','crash'])
+
+    for (k, v) in options:
+        if k in ['-L', '--live']:
+            live = True
+        if k in ['-C', '--crash']:
+            crash = True
+
+    if len(params) == 0 or len(params) > 2:
+        err("invalid number of parameters")
+        usage("dump-core")
+
+    dom = params[0]
+    if len(params) == 2:
+        filename = os.path.abspath(params[1])
+    else:
+        filename = None
+
+    if not live:
+        server.xend.domain.pause(dom)
+
+    try:
+        print "dumping core of domain:%s ..." % str(dom)
+        server.xend.domain.dump(dom, filename, live, crash)
+    finally:
+        if not live:
+            server.xend.domain.unpause(dom)
+
+    if crash:
+        print "destroying domain:%s ..." % str(dom)
+        server.xend.domain.destroy(dom)
+
 def xm_rename(args):
     arg_check(args, "rename", 2)
 
@@ -1168,6 +1210,7 @@ commands = {
     "destroy": xm_destroy,
     "domid": xm_domid,
     "domname": xm_domname,
+    "dump-core": xm_dump_core,
     "rename": xm_rename,
     "restore": xm_restore,
     "save": xm_save,